package com.example.wishstar.viewmodel;

import android.app.Application;
import android.content.Context;
import android.util.Log;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.example.wishstar.MyApplication;
import com.example.wishstar.db.UserDao;
import com.example.wishstar.db.UserDatabase;
import com.example.wishstar.model.Star;
import com.example.wishstar.repository.StarRepository;
import com.example.wishstar.repository.UserRepository;
import com.example.wishstar.utils.ApiResponse;
import com.example.wishstar.view.LoveView;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Response;

public class StarViewModel extends AndroidViewModel implements StarRepository.StarCallBack{

    private String TAG = "StarViewModel";
    private StarRepository starRepository;
    private StarCallBack starCallBack;
    private Star star;


    public interface StarCallBack {
        void callback2(int postion, Star star);
    }

    public StarViewModel(@NonNull Application application) {
        super(application);

        UserDatabase userDatabase = MyApplication.getUserDatabase();
        UserDao userDao = userDatabase.userDao();
        starRepository = new StarRepository(userDao, MyApplication.getApi());
        starRepository.refreshStar();
    }

    public void getStar(int postion) {
        starRepository.getAStar(postion, this);
    }

    public void refreshStar() {
        starRepository.refreshStar();
    }

    public void setCallBack(StarCallBack starCallBack){
        this.starCallBack = starCallBack;
    }

    @Override
    public void callback1(int postion, Star star) {
        Log.e(TAG, "callback1：" + star.toString());
        this.star = star;
        starCallBack.callback2(postion, star);
    }

    public void addWishFavourNum(int wishId) {
        starRepository.addWishFavourNum(wishId);
    }
}
